package com.daocao.yfb.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import butterknife.BindView;
import butterknife.ButterKnife;
import com.daocao.yfb.R;
import com.daocao.yfb.activity.PointDetailActivity;
import com.daocao.yfb.api.model.IndexModel;


/**
 * Created by xsooy-pc on 2017/10/23.
 */

public class HomeAdapter extends ItemAdapter<IndexModel.DatasBean.GoodsBean, HomeAdapter.DefaultHolder> {


    private Context context;

    public HomeAdapter(Context context) {
        super(context);
        this.context = context;
    }

    @Override
    public DefaultHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new DefaultHolder(inflate(R.layout.item_home, parent));
    }

    @Override
    public void onBindViewHolder(DefaultHolder holder, int position) {
        IndexModel.DatasBean.GoodsBean item = getItem(position);
        holder.layoutTotal.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, PointDetailActivity.class);
                intent.putExtra("id", item.id);
                context.startActivity(intent);
            }
        });
        holder.txtTitle.setText(item.name);
        holder.txtMerchant.setText(item.merchant);
        holder.txtMoney.setText("￥" + item.money);
        holder.txtSuccessNum.setText("已成交:" + item.buy_count + "笔");
        Glide.with(context).load(item.icon).into(holder.imgHead);
    }

    class DefaultHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.txt_title)
        TextView txtTitle;
        @BindView(R.id.txt_money)
        TextView txtMoney;
        @BindView(R.id.txt_success_num)
        TextView txtSuccessNum;
        @BindView(R.id.txt_merchant)
        TextView txtMerchant;
        @BindView(R.id.layout_total)
        LinearLayout layoutTotal;
        @BindView(R.id.img_head)
        ImageView imgHead;
        public DefaultHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    private OnChooseListener onChooseListener;

    public void setOnChooseListener(OnChooseListener onChooseListener) {
        this.onChooseListener = onChooseListener;
    }

    public interface OnChooseListener {
        void onClick(String id);
    }
}
